﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.OracleClient;

namespace Projekt_GUI
{
    public partial class Form1 : Form
    {
        public static string CONFIG_DB_HOST = "";
        public static string CONFIG_DB_PASS = "";
        public static string CONFIG_DB_USER = "";

        public static Dictionary<string, string> Cart = new Dictionary<string, string>(); //ID, Name | Reisen
        public static Dictionary<string, string> CartExt = new Dictionary<string, string>(); //ID, Name | Erweiterungen
        public static string KundenID = "";

        public Form1()
        {
            InitializeComponent();
        }

        private void bearbeitenToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void kundToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Forms.KundeNeu kn = new Forms.KundeNeu();
            kn.MdiParent = this;
            kn.Show();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            if (!File.Exists("db.config"))
            {
                File.WriteAllText("db.config", "HOST=localhost\nUSER=Projekt\nPASS=Projekt");
                CONFIG_DB_HOST = "localhost";
                CONFIG_DB_PASS = "Projekt";
                CONFIG_DB_USER = "Projekt";
            }
            else
            {
                string[] lines = File.ReadAllLines("db.config");
                foreach (string s in lines)
                {
                    string[] parts = s.Split('=');
                    if (parts[0] == "PASS")
                        CONFIG_DB_PASS = parts[1];
                    if (parts[0] == "USER")
                        CONFIG_DB_USER = parts[1];
                    if (parts[0] == "HOST")
                        CONFIG_DB_HOST = parts[1];
                }
            }

            WindowState = FormWindowState.Maximized;
        }

        private void kundenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Forms.KundeÜbersicht ku = new Forms.KundeÜbersicht();
            ku.MdiParent = this;
            ku.Show();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            Forms.KundeÜbersicht ku = new Forms.KundeÜbersicht();
            ku.MdiParent = this;
            ku.Show();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            Forms.KundeNeu kn = new Forms.KundeNeu();
            kn.MdiParent = this;
            kn.Show();
        }

        private void locationsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Forms.LocationsUebersicht loc = new Forms.LocationsUebersicht();
            loc.MdiParent = this;
            loc.Show();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            Forms.DBConfig dbc = new Forms.DBConfig();
            dbc.ShowDialog();
        }

        private void überToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AboutBox1 ab = new AboutBox1();
            ab.ShowDialog();
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            Forms.KundeNeu kn = new Forms.KundeNeu();
            kn.MdiParent = this;
            kn.Show();
            Forms.KundeÜbersicht ku = new Forms.KundeÜbersicht();
            ku.MdiParent = this;
            ku.Show();
            Forms.ReisenUebersicht ru = new Forms.ReisenUebersicht();
            ru.MdiParent = this;
            ru.Show();

            Forms.MitarbeiterUebersicht mu = new Forms.MitarbeiterUebersicht();
            mu.MdiParent = this;
            mu.WindowState = FormWindowState.Minimized;
            mu.Show();

            Forms.LocationsUebersicht lu = new Forms.LocationsUebersicht();
            lu.MdiParent = this;
            lu.WindowState = FormWindowState.Minimized;
            lu.Show();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                using (OracleConnection con = new OracleConnection("Data Source=" + Form1.CONFIG_DB_HOST + "; User Id=" + Form1.CONFIG_DB_USER + "; Password=" + Form1.CONFIG_DB_PASS))
                {
                    con.Open();

                    con.Close();
                }

                toolStripStatusLabel1.Image = imageList1.Images[1];
                toolStripStatusLabel1.Text = "Verbindung Erfolgreich.";
            }
            catch
            {
                toolStripStatusLabel1.Image = imageList1.Images[0];
                toolStripStatusLabel1.Text = "Verbindung Fehlgeschlagen.";
            }

            ((Timer)sender).Interval = 5000;
        }

        private void uhrToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void timer_uhr_Tick(object sender, EventArgs e)
        {
            uhr.Text = DateTime.Now.ToLongTimeString();
            uhr.Font = new Font("Arial", 18, FontStyle.Bold);
            toolStripLabel1.Font = new Font("Arial", 15);
            toolStripLabel1.Text = (Cart.Count + CartExt.Count).ToString()+" Im Warenkorb |";
        }

        private void reisenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Forms.ReisenUebersicht ru = new Forms.ReisenUebersicht();
            ru.MdiParent = this;
            ru.Show();
        }

        private void mitarbeiterToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Forms.MitarbeiterUebersicht mu = new Forms.MitarbeiterUebersicht();
            mu.MdiParent = this;
            mu.Show();
        }

        private void buchungenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Forms.BuchungUebersicht bu = new Forms.BuchungUebersicht();
            bu.MdiParent = this;
            bu.Show();
        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            Forms.Einkaufswagen ek = new Forms.Einkaufswagen();
            ek.MdiParent = this;
            ek.Show();
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            
        }

        private void toolStripLabel1_Click(object sender, EventArgs e)
        {

        }

        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }
    }
}
